﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BuildOptimizer
{
    class BoGoal
    {
        private int _maxNbTicks = 0;
        private int _nbBases = 0;
        private int[] _units = new int[Enum.GetNames(typeof(Units)).Length];
        private int[] _buildings = new int[Enum.GetNames(typeof(Buildings)).Length];
        private bool[] _upgrades = new bool[Enum.GetNames(typeof(Upgrades)).Length];

        public BoGoal(int timeLimit, int nbBases, int[] units, int[] buildings, bool[] upgrades)
        {
            _maxNbTicks = timeLimit;
            _nbBases = nbBases;
            _units = units;
            _buildings = buildings;
            _upgrades = upgrades;
        }

        public int maxNbTicks
        {
            get
            {
                return _maxNbTicks;
            }
        }
        public int nbBasesRequired
        {
            get
            {
                return _nbBases;
            }
        }
        public int nbUnitsRequired(int unitIndex)
        {
            return _units[unitIndex];
        }
        public int nbBuildingsRequired(int buildingIndex)
        {
            return _buildings[buildingIndex];
        }
        public bool isUpgradeRequired(int upgradeIndex)
        {
            return _upgrades[upgradeIndex];
        }

        public bool isReachableBy(BoGameState gs)
        {
            return (gs.nbTicksPassed <= maxNbTicks);
        }
        public bool isSatisfiedBy(BoGameState gs)
        {
            //ticks
            if (gs.nbTicksPassed > maxNbTicks)
            {
                return false;
            }
            //bases
            if (gs.nbHatcheriesAtResources < _nbBases)
            {
                return false;
            }
            //units
            for (int i = 0; i < _units.Length; i++)
            {
                if (_units[i] != -1)
                {
                    if (gs.nbUnitsBuilt(i) < _units[i])
                    {
                        return false;
                    }
                }
            }
            //buildings
            for (int i = 0; i < _buildings.Length; i++)
            {
                if (_buildings[i] != -1)
                {
                    if (gs.nbBuildingsBuilt(i) < _buildings[i])
                    {
                        return false;
                    }
                }
            }
            //upgrades
            for (int i = 0; i < _upgrades.Length; i++)
            {
                if (gs.isUpgradeBuilt(i) != _upgrades[i])
                {
                    return false;
                }
            }
            return true;
        }
    }
}
